package cn.bigfire.compiler.dragon.appendixA.handwrite.inter;

import cn.bigfire.compiler.dragon.appendixA.handwrite.symbols.Type;

public class Set extends Stmt {

    public Id id;
    public Expr expr;

    public Set(Id id, Expr expr) {
        this.id = id;
        this.expr = expr;
    }

    public Type check(Type type1, Type type2) {

        if (Type.numeric(type1) && Type.numeric(type2)) {
            return type2;
        } else if (type1 == Type.Bool && type2 == Type.Bool) {
            return type2;
        } else return null;

    }

    public void gen(){
        emit(id.toString() + " = " + expr.gen().toString());
    }

}
